# @shuaige : 陈世玉
# @name :03-post请求案例2.py
# @time :2024/9/19 下午10:49
import urllib.request
import urllib.parse

url = "https://fanyi.baidu.com/sug"
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36",
   # 'Cookie': 'BAIDUID=EB0EA0EB0EA0EB0EA0EB0EB0EB0EB0E:FG=1; BIDUPSID=EB0EA0EB0EA0EB0EA0EB0EB0EB0EB0E; PSTM=1695142457; BD_UPN=1695142457; BD_CK_SAM=1; locale=zh; Hm_lvt_64ecd82404c51e07bb49d6b3d'
}
data = {
    'kw':'red'
}
data = urllib.parse.urlencode(data).encode("utf-8")
request = urllib.request.Request(url=url, data=data, headers=headers)
response = urllib.request.urlopen(request)
html = response.read().decode("utf-8")

import json

data = json.loads(html)
print(data)
